package com.aopAnnotation;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
@Component
@Aspect
public class AopAnnotationAspect {
	@Pointcut("execution(* com.aopAnnotation.AopAnnotationBean.*(..))")
	public void pointcut(){
		
	}
	@Before("pointcut() && args(a)")
	public void before(String a) {//前置通知
		System.out.println("before：前置通知"+a);
	}
	@After("pointcut() && args(b)")
	public void after(String b){//后置通知
		System.out.println("after：后置通知"+b);
	}
	
	//返回值接收参数
	@AfterReturning(pointcut="pointcut() ",returning="returning")
	public void afterReturning(Student returning) {//有错误不执行，没有错误执行
		System.out.println("afterReturning：有错误不执行，没有错误执行"+returning);
	}
	
	@AfterThrowing(pointcut="pointcut()",throwing="e")
	public void afterThiowing (Exception e) {//有错误执行，没有错误不执行
		System.out.println("afterThiowing：有错误执行，没有错误不执行"+e);
	}
	
	@Around("pointcut() && args(aa)")
	public Object around(ProceedingJoinPoint pjp,String aa) throws Throwable {//环绕通知
		System.out.println("环绕通知：start"+aa);
		Object obj = pjp.proceed();
		System.out.println("环绕通知：close"+obj);
		return obj;
	}
}
